/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package vn.webapp.controller.cp;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import javax.servlet.http.HttpSession;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import vn.webapp.controller.BaseWeb;
import vn.webapp.dto.CoursingForm;
import vn.webapp.dto.DataPage;
import vn.webapp.model.Clas;
import vn.webapp.model.Classes;
import vn.webapp.model.Coursing;
import vn.webapp.model.Courses;
import vn.webapp.model.Teachers;
import vn.webapp.model.Sessions;
import vn.webapp.service.ClassesService;
import vn.webapp.service.CoursesService;
import vn.webapp.service.TeachersService;
import vn.webapp.service.CoursingService;
import vn.webapp.service.SessionsService;

/**
 *
 * @author Tonytran
 */
@Controller("cpCoursing")
@RequestMapping(value = {"/cp"})
public class CoursingController extends BaseWeb {

    @Autowired
    private CoursingService coursingService;
    @Autowired
    private TeachersService teachersService;
    @Autowired
    private CoursesService coursesService;
    @Autowired
    private SessionsService sessionsService;
    @Autowired
    private ClassesService classesService;
    private int nav = 8;

    /**
     *
     * @param model
     * @return
     */
    @RequestMapping(value = "/coursing", method = RequestMethod.GET)
    public String coursing(ModelMap model, HttpSession session,
    @RequestParam(value = "page", defaultValue = "0") int page) {
        int pageSize = 10;        
        DataPage<Coursing> dataCoursing = coursingService.filter(page, pageSize);
        //DataPage<Coursing> dataCoursing = coursingService.list();
        DataPage<Teachers> dataTeachers = teachersService.list();
        DataPage<Courses> dataCourses = coursesService.list();
        DataPage<Sessions> dataSessions = sessionsService.list();
        DataPage<Classes> dataClasses = classesService.list();
        
        List<Coursing> coursingUnique = dataCoursing.getData();
        Set<Coursing> dataCoursingUnique = new HashSet<Coursing>(coursingUnique);
        
        model.put("dataCoursingUnique", dataCoursingUnique);
        model.put("dataCoursing", dataCoursing);
        model.put("dataTeachers", dataTeachers);
        model.put("dataCourses", dataCourses);
        model.put("dataSessions", dataSessions);
        model.put("dataClasses", dataClasses);
        model.put("pageIndex", page);
        model.put("nav", this.nav);
        return "cp.coursing";
    }
    /**
     * 
     * @param coursingForm
     * @param session
     * @param map
     * @return 
     */
    @RequestMapping(value = "/coursing", method = RequestMethod.POST)
    public String filter(
            @ModelAttribute("coursingForm") CoursingForm coursingForm,
            HttpSession session,
            @RequestParam(value = "page", defaultValue = "0") int page,
            ModelMap map){
        
        
        return "cp.coursing";
    }

}
